package cn.mugutu.finance.controller;

import cn.mugutu.finance.annotation.SysResource;
import cn.mugutu.finance.domain.system.Resource;
import cn.mugutu.finance.service.system.ResourceService;
import cn.mugutu.finance.utils.Pager;
import cn.mugutu.finance.dto.BaseResult.EasyUIResult;
import cn.mugutu.finance.query.ResourceQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/resource")
public class ResourceController extends BaseController {

    @Autowired
    private ResourceService resourceService;

    @RequestMapping("/listUI")
    @SysResource(name = "资源管理", code = "resource:listui")
    public String listUI() {
        return "resource/list";
    }

    @RequestMapping("/list")
    @ResponseBody
    public EasyUIResult<Resource> list(ResourceQuery query, int page, int rows) {
        setEasyUIParamsInQuery(query, page, rows);
        Pager<Resource> pager = resourceService.findByPage(query);
        return new EasyUIResult<Resource>(pager.getTotalCount(), pager.getRows());
    }

}
